<?php	
class M_pre_applicants Extends MY_Model{

	public function get_applicants($id = FALSE)
	{
		if($id != FALSE){
			
			$sq= 'SELECT pre_applicants.*,
						 levels.level_desc
				  FROM pre_applicants
				  LEFT JOIN levels ON levels.level_id = pre_applicants.p_a_grade_level
				  WHERE pre_applicants.p_a_id = ?
				  ';
			$q = $this->db->query($sq,array($id));
			return $q->num_rows() >= 1 ? $q->row() : FALSE;
		}else{
			$sq= 'SELECT pre_applicants.*,
						 levels.level_desc
				  FROM pre_applicants
				  LEFT JOIN levels ON levels.level_id = pre_applicants.p_a_grade_level
				  ';
			$q = $this->db->query($sq);
			return $q->num_rows() >= 1 ? $q->result() : FALSE;
		}
	}
	
	public function assessment_fee($id = FALSE, $data = FALSE)
	{
		if($id != FALSE){
			$data['p_a_paid'] = 'yes';
			
			$this->db->where('p_a_id', $id);
			$this->db->update('pre_applicants', $data); 
			
			return $this->db->affected_rows() >=1 ? TRUE : FALSE;
		}else{
			return FALSE;
		}
	}

	public function get_guidance_approval()
	{
		$sql = "SELECT p.firstname,
					   p.middlename,
					   p.lastname,
					   p.name_ext,
					   p.previous_school,
					   e.schedule_for_testing,
					   e.applying_level_id,
					   e.guidance_school_records,
					   e.guidance_status,
					   e.guidance_recommendation,
					   e.guidance_approved,
					   level_desc,
					   l.level_desc as level_code
					   FROM enrollments e
					   LEFT JOIN profiles p ON e.e_profile_id = p.profile_id
					   LEFT JOIN levels l ON e.e_grade_level = l.level_id
					   WHERE (e.moved_to = ? OR e.guidance_approved = ?)
					   AND e.e_enrollee_type = ?
					   AND e.e_ay_id = ?";

		$query = $this->db->query($sql,array('yes',1,'new',$this->c_sy->id));
		return $query->num_rows() >= 1 ? $query->result() : FALSE;
	}

}